<template>
  <div class="data-container">
    <div class="data-header">
      <h1>游戏数据</h1>
      <div class="search-box">
        <input 
          type="text" 
          v-model="searchQuery" 
          placeholder="搜索角色、副本..."
          @input="handleSearch"
        >
        <button class="search-btn">
          <i class="fas fa-search"></i>
        </button>
      </div>
    </div>

    <div class="data-content">
      <div class="data-sidebar">
        <div class="sidebar-section">
          <h3>角色数据</h3>
          <div class="character-list">
            <div 
              v-for="character in characters" 
              :key="character.id"
              class="character-item"
              :class="{ active: selectedCharacter === character.id }"
              @click="selectCharacter(character)"
            >
              <img :src="character.avatar" :alt="character.name">
              <div class="character-info">
                <span class="character-name">{{ character.name }}</span>
                <div class="character-stats">
                  <span class="usage-rate">使用率: {{ character.usageRate }}%</span>
                  <span class="win-rate">胜率: {{ character.winRate }}%</span>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="sidebar-section">
          <h3>副本数据</h3>
          <div class="dungeon-list">
            <div 
              v-for="dungeon in dungeons" 
              :key="dungeon.id"
              class="dungeon-item"
              :class="{ active: selectedDungeon === dungeon.id }"
              @click="selectDungeon(dungeon)"
            >
              <div class="dungeon-info">
                <span class="dungeon-name">{{ dungeon.name }}</span>
                <div class="dungeon-stats">
                  <span class="clear-rate">通关率: {{ dungeon.clearRate }}%</span>
                  <span class="avg-time">平均时间: {{ dungeon.avgTime }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="data-main">
        <div v-if="selectedCharacter" class="character-detail">
          <div class="detail-header">
            <img :src="selectedCharacter.avatar" :alt="selectedCharacter.name" class="character-avatar">
            <div class="character-overview">
              <h2>{{ selectedCharacter.name }}</h2>
              <div class="character-meta">
                <span class="meta-item">
                  <i class="fas fa-users"></i>
                  使用率: {{ selectedCharacter.usageRate }}%
                </span>
                <span class="meta-item">
                  <i class="fas fa-trophy"></i>
                  胜率: {{ selectedCharacter.winRate }}%
                </span>
                <span class="meta-item">
                  <i class="fas fa-clock"></i>
                  平均战斗时长: {{ selectedCharacter.avgBattleTime }}
                </span>
              </div>
            </div>
          </div>

          <div class="detail-content">
            <div class="content-section">
              <h3>基础属性</h3>
              <div class="stats-grid">
                <div v-for="(value, key) in selectedCharacter.baseStats" :key="key" class="stat-item">
                  <span class="stat-label">{{ key }}</span>
                  <span class="stat-value">{{ value }}</span>
                </div>
              </div>
            </div>

            <div class="content-section">
              <h3>技能详情</h3>
              <div class="skills-list">
                <div v-for="skill in selectedCharacter.skills" :key="skill.id" class="skill-card">
                  <div class="skill-header">
                    <img :src="skill.icon" :alt="skill.name" class="skill-icon">
                    <div class="skill-info">
                      <h4>{{ skill.name }}</h4>
                      <span class="skill-type">{{ skill.type }}</span>
                    </div>
                  </div>
                  <p class="skill-description">{{ skill.description }}</p>
                  <div class="skill-stats">
                    <div v-for="(value, key) in skill.stats" :key="key" class="skill-stat">
                      <span class="stat-label">{{ key }}</span>
                      <span class="stat-value">{{ value }}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <div class="content-section">
              <h3>培养材料</h3>
              <div class="materials-list">
                <div v-for="material in selectedCharacter.materials" :key="material.id" class="material-card">
                  <img :src="material.icon" :alt="material.name" class="material-icon">
                  <div class="material-info">
                    <span class="material-name">{{ material.name }}</span>
                    <span class="material-count">x{{ material.count }}</span>
                  </div>
                  <div class="material-sources">
                    <span v-for="source in material.sources" :key="source" class="source-tag">
                      {{ source }}
                    </span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div v-if="selectedDungeon" class="dungeon-detail">
          <div class="detail-header">
            <h2>{{ selectedDungeon.name }}</h2>
            <div class="dungeon-meta">
              <span class="meta-item">
                <i class="fas fa-users"></i>
                通关率: {{ selectedDungeon.clearRate }}%
              </span>
              <span class="meta-item">
                <i class="fas fa-clock"></i>
                平均时间: {{ selectedDungeon.avgTime }}
              </span>
              <span class="meta-item">
                <i class="fas fa-star"></i>
                难度: {{ selectedDungeon.difficulty }}
              </span>
            </div>
          </div>

          <div class="detail-content">
            <div class="content-section">
              <h3>推荐阵容</h3>
              <div class="team-list">
                <div v-for="team in selectedDungeon.recommendedTeams" :key="team.id" class="team-card">
                  <div class="team-characters">
                    <div v-for="character in team.characters" :key="character.id" class="team-character">
                      <img :src="character.avatar" :alt="character.name">
                      <span class="character-name">{{ character.name }}</span>
                    </div>
                  </div>
                  <div class="team-stats">
                    <span class="win-rate">胜率: {{ team.winRate }}%</span>
                    <span class="avg-time">平均时间: {{ team.avgTime }}</span>
                  </div>
                </div>
              </div>
            </div>

            <div class="content-section">
              <h3>掉落物品</h3>
              <div class="drops-list">
                <div v-for="drop in selectedDungeon.drops" :key="drop.id" class="drop-card">
                  <img :src="drop.icon" :alt="drop.name" class="drop-icon">
                  <div class="drop-info">
                    <span class="drop-name">{{ drop.name }}</span>
                    <span class="drop-rate">掉落率: {{ drop.rate }}%</span>
                  </div>
                </div>
              </div>
            </div>

            <div class="content-section">
              <h3>通关攻略</h3>
              <div class="strategy-content" v-html="selectedDungeon.strategy"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'

const searchQuery = ref('')
const selectedCharacter = ref(null)
const selectedDungeon = ref(null)

// 模拟角色数据
const characters = reactive([
  {
    id: 1,
    name: '伊莉雅',
    avatar: '/characters/elisa.jpg',
    usageRate: 45.8,
    winRate: 52.3,
    avgBattleTime: '2分30秒',
    baseStats: {
      '生命值': '12000',
      '攻击力': '2800',
      '防御力': '800',
      '暴击率': '25%',
      '暴击伤害': '150%'
    },
    skills: [
      {
        id: 1,
        name: '元素爆发',
        type: '主动技能',
        icon: '/skills/burst.jpg',
        description: '释放强大的元素能量，对范围内敌人造成大量伤害。',
        stats: {
          '伤害倍率': '350%',
          '冷却时间': '12秒',
          '元素消耗': '60'
        }
      }
    ],
    materials: [
      {
        id: 1,
        name: '元素结晶',
        icon: '/materials/crystal.jpg',
        count: 168,
        sources: ['元素副本', '世界BOSS']
      }
    ]
  }
])

// 模拟副本数据
const dungeons = reactive([
  {
    id: 1,
    name: '元素试炼',
    clearRate: 78.5,
    avgTime: '3分15秒',
    difficulty: '困难',
    recommendedTeams: [
      {
        id: 1,
        characters: [
          { id: 1, name: '伊莉雅', avatar: '/characters/elisa.jpg' },
          { id: 2, name: '艾莉丝', avatar: '/characters/alice.jpg' }
        ],
        winRate: 85.2,
        avgTime: '2分45秒'
      }
    ],
    drops: [
      {
        id: 1,
        name: '元素结晶',
        icon: '/materials/crystal.jpg',
        rate: 25.5
      }
    ],
    strategy: `
      <h4>副本机制</h4>
      <p>1. 每30秒会刷新一波小怪</p>
      <p>2. 击败所有小怪后会出现BOSS</p>
      <h4>推荐打法</h4>
      <p>1. 优先清理小怪，避免被包围</p>
      <p>2. BOSS出现后注意躲避技能</p>
    `
  }
])

const handleSearch = () => {
  // TODO: 实现搜索功能
}

const selectCharacter = (character: any) => {
  selectedCharacter.value = character
  selectedDungeon.value = null
}

const selectDungeon = (dungeon: any) => {
  selectedDungeon.value = dungeon
  selectedCharacter.value = null
}
</script>

<style scoped>
.data-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.data-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.data-header h1 {
  margin: 0;
  color: #2c3e50;
}

.search-box {
  display: flex;
  gap: 0.5rem;
}

.search-box input {
  width: 300px;
  padding: 0.8rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

.search-btn {
  padding: 0.8rem;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.data-content {
  display: flex;
  gap: 2rem;
}

.data-sidebar {
  width: 300px;
  flex-shrink: 0;
}

.sidebar-section {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.sidebar-section h3 {
  margin: 0 0 1rem;
  color: #2c3e50;
}

.character-list,
.dungeon-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.character-item,
.dungeon-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem;
  background: #f5f5f5;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.character-item:hover,
.dungeon-item:hover,
.character-item.active,
.dungeon-item.active {
  background: #42b983;
  color: white;
}

.character-item img {
  width: 48px;
  height: 48px;
  border-radius: 4px;
}

.character-info,
.dungeon-info {
  flex: 1;
}

.character-name,
.dungeon-name {
  display: block;
  font-weight: 500;
  margin-bottom: 0.3rem;
}

.character-stats,
.dungeon-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
  color: #666;
}

.character-item:hover .character-stats,
.character-item.active .character-stats {
  color: rgba(255, 255, 255, 0.8);
}

.data-main {
  flex: 1;
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
}

.detail-header {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
}

.character-avatar {
  width: 120px;
  height: 120px;
  border-radius: 8px;
}

.character-overview {
  flex: 1;
}

.character-overview h2 {
  margin: 0 0 1rem;
  color: #2c3e50;
}

.character-meta,
.dungeon-meta {
  display: flex;
  gap: 2rem;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #666;
}

.content-section {
  margin-bottom: 2rem;
}

.content-section h3 {
  margin: 0 0 1rem;
  color: #2c3e50;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #eee;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  padding: 0.8rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.stat-label {
  color: #666;
}

.stat-value {
  font-weight: 500;
  color: #2c3e50;
}

.skills-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.skill-card {
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.skill-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.skill-icon {
  width: 48px;
  height: 48px;
  border-radius: 4px;
}

.skill-info h4 {
  margin: 0 0 0.3rem;
  color: #2c3e50;
}

.skill-type {
  font-size: 0.9rem;
  color: #666;
}

.skill-description {
  margin: 0 0 1rem;
  color: #666;
}

.skill-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
}

.skill-stat {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem;
  background: white;
  border-radius: 4px;
}

.materials-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

.material-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.material-icon {
  width: 48px;
  height: 48px;
  border-radius: 4px;
}

.material-info {
  flex: 1;
}

.material-name {
  display: block;
  font-weight: 500;
  color: #2c3e50;
}

.material-count {
  font-size: 0.9rem;
  color: #666;
}

.material-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.source-tag {
  padding: 0.2rem 0.5rem;
  background: white;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #666;
}

.team-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.team-card {
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.team-characters {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.team-character {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.team-character img {
  width: 64px;
  height: 64px;
  border-radius: 4px;
}

.team-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
  color: #666;
}

.drops-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.drop-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.drop-icon {
  width: 48px;
  height: 48px;
  border-radius: 4px;
}

.drop-info {
  flex: 1;
}

.drop-name {
  display: block;
  font-weight: 500;
  color: #2c3e50;
}

.drop-rate {
  font-size: 0.9rem;
  color: #666;
}

.strategy-content {
  line-height: 1.6;
  color: #2c3e50;
}

.strategy-content h4 {
  margin: 1.5rem 0 1rem;
  color: #2c3e50;
}

.strategy-content p {
  margin: 0.5rem 0;
}
</style> 